package feeinterface.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import feeinterface.dao.TestDao;

/**
 * Servlet implementation class CheckApplicationServer
 * 
 * 该servlet仅供后台页面访问，通过访问到该Servlet来查看服务器是否挂掉，Servlet会调用dao层接口，测试是否
 * 能正常连接从库和主库，如果整个流程都能走完，则返回ok，如果不可以则返回error
 */
public class CheckApplicationServer extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public CheckApplicationServer() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String msg = "";
		if(!TestDao.testConnectMainDB()){
			msg += "主数据库连接有问题！！";
		}
		if(!TestDao.testConnectSlaveDB()){
			msg += "从数据库连接有问题!!";
		}
		if(msg.trim().equals(""))
			msg = "ok";
		response.setCharacterEncoding("UTF-8");
		response.addHeader("Access-Control-Allow-Origin", "*");
		response.getWriter().write(msg);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
